# psutil and tk
# 点击按钮, 显示 cpu 核数, cpu 使用率

import psutil
import tkinter
from tkinter import *

root = tkinter.Tk()
root.title('NO.Three')
root.geometry('800x600')

font1 = ('楷体',15)
label = tkinter.Label(text = '点击按钮可获取 Local pc 内核',width=30,font=font1)
label.place(x=150,y=80)


def logic():
    res = psutil.cpu_count()
    return res
def core():
    res = psutil.cpu_count(False)
    return res
def usage():
    res = psutil.cpu_freq()
    return res

def tishi(event):
    logic1 = str(logic())
    core1 = str(core())
    usage1 = str(usage())

    logic2 = '逻辑内核:{}'.format(logic1)
    core2 = '内核{}'.format(core1)
    usage2 = '使用频率{}'.format(usage1)
    m = StringVar()
    list_box = tkinter.Listbox(root, listvariable=m, height=3, width=55, fg='green')
    for i in [logic2, core2, usage2]:
        list_box.insert(END, i)
    list_box.place(x=150, y=250)

button = tkinter.Button(text = '确定',bg='skyblue',font = font1)
button.bind('<Button-1>',tishi)
button.place(x=400,y=110)

root.mainloop()

